package com.sasken.pdb.views.renderers
{
	import mx.containers.Canvas;
	import mx.controls.AdvancedDataGrid;
	import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
	import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;
	import mx.controls.listClasses.BaseListData;
	import mx.controls.listClasses.IDropInListItemRenderer;
	import mx.controls.listClasses.IListItemRenderer;
	import mx.core.IDataRenderer;
	import mx.core.UIComponentGlobals;
	import mx.core.mx_internal;
	import mx.events.FlexEvent;
	
	use namespace mx_internal;
	
	[Event(name="dataChange", type="mx.events.FlexEvent")]
	/**
	 *  A renderer which extends from Canvas, unlike the default renderer which extends from Label.
	 *  This enables its user to render anything they want in a cell item. 
	 *  Intended for base class usage only.  
	 */ 
	public class CanvasItemRenderer extends Canvas 
	implements IDropInListItemRenderer, IListItemRenderer, IDataRenderer
	{
		protected var _listData:AdvancedDataGridListData;
	    /**
	     *  @private
	     */
	    private var _data:Object;		
	    /**
	     *  @private
	     */
	    private var invalidatePropertiesFlag:Boolean = false;		
	    /**
	     *  @private
	     */
	    private var invalidateSizeFlag:Boolean = false;
	    		
		public function CanvasItemRenderer()
		{
			percentHeight = 100;
			percentWidth = 100;
		}
		
	    /**
	     *  The implementation of the <code>data</code> property as 
	     *  defined by the IDataRenderer interface.
	     *  The value is ignored.  Only the <code>listData</code> property is used.
	     *
	     *  @see mx.core.IDataRenderer
	     */
	    public override function get data():Object
	    {
	        return _data;
	    }
	    
	    /**
	     *  @private
	     */
	    public override function set data(value:Object):void
	    {
	        _data = value;
	
	        dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
	    }		
		
		public function get listData():BaseListData
		{
			return _listData;
		}
		
    	public function set listData(value:BaseListData):void
    	{
			_listData = AdvancedDataGridListData(value);
	        if (nestLevel && !invalidatePropertiesFlag)
	        {
	            UIComponentGlobals.layoutManager.invalidateProperties(this);
	            invalidatePropertiesFlag = true;
	            UIComponentGlobals.layoutManager.invalidateSize(this);
	            invalidateSizeFlag = true;
	        }
    	}
    	
    	/**
	     *  @private
	     */
	    override public function set nestLevel(value:int):void
	    {
	        super.nestLevel = value;
	    
	        UIComponentGlobals.layoutManager.invalidateProperties(this);
	        invalidatePropertiesFlag = true;
	        
	        UIComponentGlobals.layoutManager.invalidateSize(this);
	        invalidateSizeFlag = true;
	    }
	    
	    override public function validateProperties():void
	    {
	    	super.validateProperties();
	    }

	}
}